package com.xhd.base.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Date extends java.util.Date
{
  private static final long jm51 = 1L;
  public static final int YEAR = 1;
  public static final int MONTH = 2;
  public static final int DATE = 5;
  public static final int HOUR = 11;
  public static final int MINUTE = 12;
  public static final int SECOND = 13;
  public static final int MILLISECOND = 14;

  public Date()
  {
    setTime(System.currentTimeMillis());
  }

  public Date(long paramLong)
  {
    super(paramLong);
  }

  public Date(String paramString)
  {
    if ((paramString == null) || (paramString.length() <= 0))
      return;
    SimpleDateFormat localSimpleDateFormat = null;
    if (paramString.length() == 19)
    {
      localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
    else if (paramString.length() == 10)
    {
      localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    }
    else if (paramString.length() == 8)
    {
      localSimpleDateFormat = new SimpleDateFormat("HH:mm:ss");
    }
    else
    {
      String str = "";
      String[] arrayOfString = (String[])null;
      int i = -1;
      i = paramString.indexOf(32);
      if (i > 0)
      {
        arrayOfString = new String[2];
        arrayOfString[0] = paramString.substring(0, i);
        arrayOfString[1] = paramString.substring(i, paramString.length());
      }
      else
      {
        arrayOfString = new String[1];
        arrayOfString[0] = paramString;
      }
      for (int j = 0; j < arrayOfString.length; ++j)
      {
        if (j > 0)
          str = str + " ";
        i = arrayOfString[j].indexOf(45);
        int k;
        if (i > 0)
        {
          k = 0;
          while (i > 0)
          {
            ++k;
            i = arrayOfString[j].indexOf(45, i + 1);
          }
          if (k == 1)
          {
            str = str + "yy-M";
          }
          else
          {
            if (k != 2)
              continue;
            str = str + "yy-M-d";
          }
        }
        else
        {
          i = arrayOfString[j].indexOf(58);
          if (i <= 0)
            continue;
          k = 0;
          while (i > 0)
          {
            ++k;
            i = arrayOfString[j].indexOf(58, i + 1);
          }
          if (k == 1)
          {
            str = str + "H:m";
          }
          else
          {
            if (k != 2)
              continue;
            str = str + "H:m:s";
          }
        }
      }
      if (str.length() > 0)
        localSimpleDateFormat = new SimpleDateFormat(str);
    }
    if (localSimpleDateFormat == null)
      return;
    try
    {
      setTime(localSimpleDateFormat.parse(paramString).getTime());
    }
    catch (ParseException localParseException)
    {
      localParseException.printStackTrace();
    }
  }

  public void add(int paramInt1, int paramInt2)
  {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTime(this);
    localCalendar.add(paramInt1, paramInt2);
    setTime(localCalendar.getTime().getTime());
  }

  public int compareTo(int paramInt, java.util.Date paramDate)
  {
    int i = 0;
    int j = 0;
    int k = 0;
    int l = 0;
    int i1 = 0;
    Calendar localCalendar = Calendar.getInstance();
    switch (paramInt)
    {
    case 1:
      localCalendar.setTime(this);
      j = localCalendar.get(1);
      localCalendar.setTime(paramDate);
      i = j - localCalendar.get(1);
      break;
    case 2:
      localCalendar.setTime(this);
      j = localCalendar.get(1);
      k = localCalendar.get(2);
      localCalendar.setTime(paramDate);
      i = j - localCalendar.get(1);
      i = k - localCalendar.get(2) + i * 12;
      break;
    case 5:
      localCalendar.setTime(this);
      j = localCalendar.get(1);
      l = localCalendar.get(6);
      localCalendar.setTime(paramDate);
      i = j - localCalendar.get(1);
      i = l - localCalendar.get(6) + i * 365;
      break;
    case 11:
      localCalendar.setTime(this);
      j = localCalendar.get(1);
      l = localCalendar.get(6);
      i1 = localCalendar.get(11);
      localCalendar.setTime(paramDate);
      i = j - localCalendar.get(1);
      i = l - localCalendar.get(6) + i * 365;
      i = i1 - localCalendar.get(11) + i * 24;
    }
    return i;
  }

  public static String dateStringToXMLText(String paramString)
    throws Exception
  {
    if ((paramString == null) || (paramString.equals("")))
      return "";
    try
    {
      SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      java.util.Date localDate = localSimpleDateFormat1.parse(paramString);
      SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
      String str = localSimpleDateFormat2.format(localDate);
      return str;
    }
    catch (ParseException localParseException)
    {
      throw localParseException;
    }
  }

  public void exactAdd(int paramInt, float paramFloat)
  {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTime(this);
    localCalendar.add(paramInt, (int)paramFloat);
    int i = 0;
    switch (paramInt)
    {
    case 5:
      i = (int)(24.0F * (paramFloat - (int)paramFloat));
      if (i > 0)
        localCalendar.add(10, i);
      break;
    case 11:
      i = (int)(60.0F * (paramFloat - (int)paramFloat));
      if (i > 0)
        localCalendar.add(12, i);
    }
    setTime(localCalendar.getTime().getTime());
  }

  public float exactCompareTo(int paramInt, java.util.Date paramDate)
  {
    float f = 0.0F;
    int i = 0;
    int j = 0;
    int k = 0;
    int l = 0;
    Calendar localCalendar = Calendar.getInstance();
    switch (paramInt)
    {
    case 5:
      localCalendar.setTime(this);
      i = localCalendar.get(1);
      j = localCalendar.get(6);
      k = localCalendar.get(11);
      localCalendar.setTime(paramDate);
      f = i - localCalendar.get(1);
      f = j - localCalendar.get(6) + f * 365.0F;
      k -= localCalendar.get(11);
      f = (float)(f + k / 24.0D);
      break;
    case 11:
      localCalendar.setTime(this);
      i = localCalendar.get(1);
      j = localCalendar.get(6);
      k = localCalendar.get(11);
      l = localCalendar.get(12);
      localCalendar.setTime(paramDate);
      f = i - localCalendar.get(1);
      f = j - localCalendar.get(6) + f * 365.0F;
      f = k - localCalendar.get(11) + f * 24.0F;
      l -= localCalendar.get(12);
      f = (float)(f + l / 60.0D);
    }
    return f;
  }

  public int get(int paramInt)
  {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTime(this);
    if (paramInt == 2)
      return (localCalendar.get(paramInt) + 1);
    return localCalendar.get(paramInt);
  }

  public static String getToday()
  {
    Date localDate = new Date();
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return localSimpleDateFormat.format(localDate);
  }

  public String toDateText()
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    return localSimpleDateFormat.format(this);
  }

  public static String toDBFormatText(String paramString)
  {
    if ((paramString == null) || (paramString.equals("")))
      return null;
    try
    {
      SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
      java.util.Date localDate = localSimpleDateFormat1.parse(paramString);
      SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      String str = localSimpleDateFormat2.format(localDate);
      return str;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public String toText()
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return localSimpleDateFormat.format(this);
  }

  public static String toText(java.util.Date paramDate)
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    return localSimpleDateFormat.format(paramDate);
  }

  public String toText1()
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("yyyyMMdd");
    return localSimpleDateFormat.format(this);
  }

  public String toTimeText()
  {
    SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("HH:mm:ss");
    return localSimpleDateFormat.format(this);
  }

  public int getLast(int paramInt)
  {
    Calendar localCalendar = Calendar.getInstance();
    localCalendar.setTime(this);
    if (paramInt == 2)
      return (localCalendar.getActualMaximum(paramInt) + 1);
    return localCalendar.getActualMaximum(paramInt);
  }
}